﻿function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function Get_Cookie (check_name) {
var a_all_cookies = document.cookie.split( ';' );
var a_temp_cookie = '';
var cookie_name = '';
var cookie_value = '';
var b_cookie_found = false;
for ( i = 0; i < a_all_cookies.length; i++ ){
	a_temp_cookie = a_all_cookies[i].split( '=' );
	cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	if ( cookie_name == check_name ){
		b_cookie_found = true;
		if ( a_temp_cookie.length > 1 ){
			cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
		}
		return cookie_value;
		break;
	}
	a_temp_cookie = null;
	cookie_name = '';
}
if ( !b_cookie_found )
	{
		return null;
	}
}


function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( 
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 
			

function GetDataqID(){
		var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		var string_length = 12;
		var IDVal = '';
		FirstTimeStamp = new Date();
		for (var i=0; i<string_length; i++) {
			var rnum = Math.floor(Math.random() * chars.length);
			IDVal += chars.substring(rnum,rnum+1);
		}
		DataqUserID = FirstTimeStamp + "_" + IDVal;
		createCookie('DataqID', DataqUserID, 7300);
}

function TestCookie(){
var exp = new Date();
exp.setTime(exp.getTime() + 1800000);
	if (!Get_Cookie('DataqID')) {
		GetDataqID();
	}
}

TestCookie();